package com.livesource.server.database.project;

import com.google.appengine.repackaged.org.json.JSONException;
import com.google.appengine.repackaged.org.json.JSONObject;
import com.googlecode.objectify.Objectify;
import com.livesource.server.database.ObjectifyServiceCreation;
import com.livesource.server.model.project.Project;

public class GetProject {

	public static JSONObject jsonEntity(String projectID) {

		return jsonEntity(get(projectID));
	}

	public static Project get(String projectID) {

		Project project = null;

		if (projectID != null) {

			Objectify objfyService = ObjectifyServiceCreation.gerService();

			project = objfyService.get(Project.class, projectID);
		}

		return project;
	}

	// SaveProject.save(ProjectsData.loadProjectTicTacToe());
	// SaveProject.save(ProjectsData.loadProjectTravelLog());

	public static JSONObject jsonEntity(Project project) {

		JSONObject jsonEntity = null;

		try {

			jsonEntity = new JSONObject();

			jsonEntity.put("projectID", project.getProjectID());

			jsonEntity.put("projectName", project.getProjectName());

			jsonEntity
					.put("projectRepositoryType", project.getRepositoryType());

			jsonEntity.put("projectRepositoryURL", project.getRepositoryURL());

		} catch (JSONException e) {

			e.printStackTrace();
		}

		return jsonEntity;
	}
}